<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-s-order"></i> 订单列表  
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="orderSn" placeholder="请搜索订单编号" class="handle-input mr10"  @keyup.enter.native="handleSearch"></el-input>
                    <el-select v-model="value" placeholder="请选择商家店铺" @change="change">
                        <el-option v-for="item in shopList" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                    </el-select>
                <el-button type="primary" icon="el-icon-search" style="margin-left: 20px;" @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="id" label="用户ID" width="55" align="center"></el-table-column>
                <el-table-column prop="f_wx_no" label="订单编号"></el-table-column>
                <el-table-column prop="has_shop.f_shop_name" label="商家店铺"></el-table-column>
                <el-table-column prop="has_user.f_nickName" label="用户名称"></el-table-column>
                <el-table-column prop="f_start_time" label="开台时间"></el-table-column>
                <el-table-column prop="f_eq_no" label="桌台号码"></el-table-column>
                <el-table-column prop="f_cash_pledge" label="押金金额"></el-table-column>
                
                <el-table-column label="桌台类型"  align="center">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.f_eq_type == 2" >麻将</el-tag>
                        <el-tag v-if="scope.row.f_eq_type == 1" >台球</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="f_coupon_money" label="优惠券抵扣"></el-table-column>
                <el-table-column prop="f_end_time" label="关台时间"></el-table-column>
                <el-table-column prop="f_pay_money" label="实付款"></el-table-column>
                <el-table-column label="订单状态" align="center">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.f_status == 2" type="success">已结束</el-tag>
                        <el-tag v-if="scope.row.f_status == 1" type="success">进行中</el-tag>
                        <el-tag v-if="scope.row.f_status == 0" type="success">未付款</el-tag>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.page"
                    :page-size="query.pageNum"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
        <!-- 查看弹窗 -->
        <el-dialog title="查看弹窗" :visible.sync="editVisible" width="1000px" append-to-body>
            <el-form ref="form" :model="form" label-width="100px">
                <div style="display: flex">
                    <el-form-item label="商家姓名:">
                        <div>{{ form.f_nickName }}</div>
                    </el-form-item>
                    <el-form-item label="ID:" style="margin-left: 100px;">
                        <div>{{ form.id }}</div>
                    </el-form-item>
                    <el-form-item label="用户身份:" style="margin-left: 120px;">
                        <div>{{ form.f_is_c == 1 ? '用户' : '商家' }}</div>
                    </el-form-item>

                </div>
            </el-form>
            
        </el-dialog>
    </div>
</template>

<script>
import { getAdminOrderList,shopList} from '../../../api/index';
export default {
    name: 'orderList',
    data() {
        return {
            value: '',
            shopList: [
                {
                    label: '',
                    value: ''
                }
            ],
            query: {
                page:1,
                pageNum:15,
                orderSn:'',
                shopId:''
            },
            tableData: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            form: {},
            orderSn:'',
            idx: -1,
            id: -1,
            shopId:''
        };
    },
    created() {
        this.getData();
        this.shop();
    },
    methods: {
         // 店铺列表数据
         shop() {
            shopList({
                type: 2 //商家列表
            }).then((res) => {
                let arr = res.data;
                this.shopList = arr.map((item) => {
                    return {
                        label: item.f_shop_name,
                        value: item.id
                    };
                });

               
            });
        },
        // 获取 easy-mock 的模拟数据
        getData() {
            getAdminOrderList(this.query).then(res => {
                console.log(res.data.list,'getData');
                this.tableData = res.data.list;
                this.pageTotal = res.data.count|| 50;
            });
        },
        change(e){
            this.shopId = e
            console.log(e,'[[[[[[[[[[[]]]]]]]]]]]')
        },
        
        // 触发搜索按钮
        handleSearch() {
            // if (this.orderSn == '') {
            //     this.getData();
            //     return
            // }
            console.log(this.orderSn, '商家姓名');
            getAdminOrderList({
                page: 1,
                pageNum: 15,
                orderSn:this.orderSn,
                shopId:this.shopId
            }).then((res) => {
                console.log(res.data.list, '商家列表');
                this.tableData = res.data.list;
                this.pageTotal =  res.data.count || 50;

            });
        },
        // 分页导航
        handlePageChange(val) {
            console.log(val,'分页导航val')
            this.query.orderSn = this.orderSn,
            this.query.shopId = this.shopId
            this.$set(this.query, 'page', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.green {
    color: rgb(38, 141, 38);
}
.red {
    color: red;

}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
